package edu.gmu.projects.fireresponder.gui;

import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;
import edu.gmu.projects.fireresponder.R;
import edu.gmu.projects.fireresponder.environment.Path;
import edu.gmu.projects.fireresponder.environment.Safespot;

public class AssetDialogInfoTab extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.asset_info_tab);

		Bundle bundle = getIntent().getExtras();

		String assetId = bundle.getString(SituationMap.ASSET_ID);
		String assetClass = bundle.getString(SituationMap.ASSET_CLASS);
		double probFire = bundle.getDouble(SituationMap.PROB_FIRE);
		double probPeople = bundle.getDouble(SituationMap.PROB_PEOPLE);
		double relevance = bundle.getDouble(SituationMap.RELEVANCE);
		double fireDistance = bundle.getDouble(SituationMap.FIRE_DISTANCE);
		int timeToAsset = bundle.getInt(SituationMap.TIME_TO_ASSET);
		double probFireAtTime = bundle
				.getDouble(SituationMap.PROB_FIRE_AT_TIME);

		String title = "";
		String fDistStr = "";
		String assetTimeStr = "";
		String probFireStr = String.format("%.2f%%", probFire * 100);
		String probPeopleStr = String.format("%.2f%%", probPeople * 100);
		String relevanceStr = String.format("%.2f%%", relevance * 100);
		String probFireAtTimeStr = String
				.format("%.2f%%", probFireAtTime * 100);

		if (assetClass.compareTo(Path.class.getName()) == 0) {
			title = "Path " + assetId;
		} else if (assetClass.compareTo(Safespot.class.getName()) == 0) {
			title = "Safespot " + assetId;
		} else {
			title = assetId;
		}

		if (fireDistance > 5) {
			fDistStr = "> 5 km";
		} else if (fireDistance > 0.5) {
			fDistStr = String.format("%d km", (int) fireDistance);
		} else {
			fDistStr = String.format("%d m", (int) (fireDistance * 1000));
		}

		if (timeToAsset > 3600) {
			assetTimeStr = "> 1 hour";
		} else if (timeToAsset < 60) {
			assetTimeStr = "< 1 min";
		} else {
			assetTimeStr = String.format("%d min", (int) (timeToAsset / 60));
		}

		String text = "";
		if (assetClass.compareTo(SituationMap.NO_VALUE) != 0) {
			text = String.format("%s\n\n" + "Asset Info\n"
					+ "Fire Probability: %s\n" + "People Probability: %s\n"
					+ "Mission Relevance: %s\n" + "Approx Dist to Fire: %s\n\n"
					+ "Future Asset Info\n" + "ETA to Asset: %s\n"
					+ "Fire Prob Guess: %s", title, probFireStr, probPeopleStr,
					relevanceStr, fDistStr, assetTimeStr, probFireAtTimeStr);
		} else {
			text = String.format("%s\n\n" + "Info\n"
					+ "Fire Probability: %s\n" + "People Probability: %s\n"
					+ "Mission Relevance: %s\n" + "Approx Dist to Fire: %s",
					title, probFireStr, probPeopleStr, relevanceStr, fDistStr);

		}

		TextView textview = (TextView) findViewById(R.id.infoTabTextView);
		textview.setMovementMethod(new ScrollingMovementMethod());
		textview.setText(text);
	}
}